﻿#region File Header

/* File Name    : FacebookCommentManager.cs
 * Description  : Manage comments on Facebook
 * Log
 * Date             Author              Description
 * 19-Oct-2011      Robin Jome          Class is created
 */

#endregion

#region Namespaces

using FacebookAPI.Base;
using FacebookAPI.FacebookProperties;
using FacebookAPI.Objects;

#endregion

namespace FacebookAPI.Managers
{
    #region Class

    /// <summary>
    /// Manage comments on Facebook
    /// </summary>
    public class FacebookCommentManager
    {
        #region Methods

        /// <summary>
        /// Creates a comment on a Facebook object
        /// </summary>
        /// <param name="ownerObjectId">The Id of the object on which comment should be posted</param>
        /// <param name="comment">The Facebook comment object</param>
        /// <param name="accessToken">The Facebook access token</param>
        /// <returns>Returns the Id of the newly created Comment</returns>
        public string CreateComment(string ownerObjectId, Comment comment, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            FacebookBaseObject response = mgr.SaveObject<FacebookBaseObject>(mgr.GetUrl(ownerObjectId, FacebookConnections.Comments, accessToken),comment.GetPostData());
            return (response != null) ? response.Id : string.Empty;
        }

        /// <summary>
        /// Deletes a comment
        /// </summary>
        /// <param name="commentId">The id of the comment</param>
        /// <param name="accessToken">The Facebook access token</param>
        /// <returns>Returns true if deleted</returns>
        public bool DeleteComment(string commentId, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            return mgr.DeleteObject<bool>(mgr.GetUrl(commentId, null, accessToken));
        }

        /// <summary>
        /// Likes a comment
        /// </summary>
        /// <param name="commentId">The Id of the Facebook comment</param>
        /// <param name="accessToken">The Facebook access token</param>
        /// <returns>Returns true if liked the comment</returns>
        public bool LikeTheComment(string commentId, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            return mgr.SaveObject<bool>(mgr.GetUrl(commentId, FacebookConnections.Likes, accessToken));
        }

        /// <summary>
        /// Un-likes a comment
        /// </summary>
        /// <param name="commentId">The Id of the Facebook post</param>
        /// <param name="accessToken">The Facebook access token</param>
        /// <returns>Returns true if unlike was successful</returns>
        public bool UnlikeTheComment(string commentId, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            return mgr.DeleteObject<bool>(mgr.GetUrl(commentId, FacebookConnections.Likes, accessToken));
        }

        #endregion

        #region Connections

        /// <summary>
        /// Gets the list of users who liked a comment
        /// </summary>
        /// <param name="commentId">The Id of the Facebook comment</param>
        /// <param name="accessToken">The Facebook access token</param>
        /// <param name="searchOptions">The search options to be used</param>
        /// <returns>Returns a list of Users(Id,Name) who liked the Facebook post</returns>
        public FacebookConnection<FacebookBaseObject> GetLikes(string commentId, SearchOptions searchOptions, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            return mgr.GetConnectionObject<FacebookBaseObject>(mgr.GetUrl(commentId, FacebookConnections.Likes, null, searchOptions, accessToken, false));
        }

        #endregion
    }

    #endregion
}
